//
//  ApplyForHelpViewController.m
//  WideHelp
//
//  Created by ENERGY on 2018/8/14.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "ApplyForHelpViewController.h"
#import "MemberStoryTableViewCell.h"
@interface ApplyForHelpViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, strong)UIView * headerView;
@property (nonatomic, strong)NSMutableArray * cellData;
@end

@implementation ApplyForHelpViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"申请互助";
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self.view addSubview:self.tableView];
}
#pragma mark - init
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - BOTTOM_HEIGHT - NAVI_HEIGHT) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerClass:[MemberStoryTableViewCell class] forCellReuseIdentifier:NSStringFromClass([MemberStoryTableViewCell class])];
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.tableHeaderView = self.headerView;
    }return _tableView;
}
- (NSMutableArray *)cellData{
    if (!_cellData) {
        _cellData =@[
                     @{@"content":@"是四大是四大是四大是四大是四大是四大是四大是四大是四大是四大是四大是四大是四大是四大"},
                     @{@"content":@"飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒飒"},
                     @{@"content":@"打算打算打算打实打实的打算打算打算打实打实的打算打算打算打实打实的打算打算打算打实打实的打算打算打算打实打实的打算打算打算打实打实的打算打算打算打实打实的打算打算打算打实打实的打算打算打算打实打实的打算打算打算打实打实的打算打算打算打实打实的"},].mutableCopy;
    }return _cellData;
}
- (UIView *)headerView{
    if (!_headerView) {
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 78/WIDTH_6_SCALE)];
        _headerView.backgroundColor = getColor(@"f5f5f5");
        //白色背景
        UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 69/WIDTH_6_SCALE)];
        whiteView.backgroundColor = [UIColor whiteColor];
        [_headerView addSubview:whiteView];
        //顶部分割线
        UIView * topLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1/WIDTH_6_SCALE)];
        topLineView.backgroundColor = getColor(@"eeeeee");
        [_headerView addSubview:topLineView];
        //说明标题
        UILabel * titleLab = [[UILabel alloc] initWithFrame:CGRectMake(15/WIDTH_6_SCALE, 18/WIDTH_6_SCALE + topLineView.bottom, SCREEN_WIDTH - 30/WIDTH_6_SCALE, 15/WIDTH_6_SCALE)];
        [self label:titleLab withFont:DEF_FontSize_14 withText:@"如已度过等待期，切需申请互助金，请拨打" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:whiteView withBGColor:[UIColor clearColor]];
        //电话
        UILabel * phoneLab = [[UILabel alloc] initWithFrame:CGRectMake(titleLab.left, titleLab.bottom + 5/WIDTH_6_SCALE, titleLab.width, 13/WIDTH_6_SCALE)];
        [self label:phoneLab withFont:DEF_FontSize_14 withText:@"400-888-8888" withTextColor:getColor(greenBGColor) withTextAlignment:NSTextAlignmentLeft withView:whiteView withBGColor:[UIColor clearColor]];
    }return _headerView;
}
#pragma mark - tableViewDelegate和tableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MemberStoryTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MemberStoryTableViewCell class]) forIndexPath:indexPath];
    cell.model = self.cellData[indexPath.row];
    if (indexPath.row == 0) {
        cell.topVerticalDashLine.hidden = YES;
    }else{
        cell.topVerticalDashLine.hidden = NO;
    }
    if (indexPath.row == self.cellData.count - 1) {
        cell.bottomVerticalDashLine.hidden = YES;
    }else{
        cell.bottomVerticalDashLine.hidden = NO;
    }return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.cellData.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [MemberStoryTableViewCell heightForCellWithComment:self.cellData[indexPath.row]];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * sectionHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 41/WIDTH_6_SCALE)];
    sectionHeaderView.backgroundColor = [UIColor whiteColor];
    UILabel * titleLab = [[UILabel alloc] initWithFrame:CGRectMake(15/WIDTH_6_SCALE, 0, 150/WIDTH_6_SCALE, sectionHeaderView.height - 1/WIDTH_6_SCALE)];
    [self label:titleLab withFont:DEF_FontSize_14 withText:@"互助流程" withTextColor:[UIColor blackColor] withTextAlignment:NSTextAlignmentLeft withView:sectionHeaderView withBGColor:[UIColor clearColor]];
    UIView * lineView = [[UIView alloc] initWithFrame:CGRectMake(0, sectionHeaderView.bottom - 1/WIDTH_6_SCALE, SCREEN_WIDTH, 1/WIDTH_6_SCALE)];
    lineView.backgroundColor = getColor(@"eeeeee");
    [sectionHeaderView addSubview:lineView];
    return sectionHeaderView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 41/WIDTH_6_SCALE;
}
@end
